package 动态代理.JDK实现;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 *
 */
public class Man implements People {

    public void say() {

        System.out.println("say hello");

    }

    public static void main(String[] args) {

        // 真实对象
        Man realMan = new Man();

        People proxyInstance = (People) Proxy.newProxyInstance(Man.class.getClassLoader(), Man.class.getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

                System.out.println("do something before");

                method.invoke(realMan, args);

                System.out.println("do something after");

                return null;
            }
        });

        proxyInstance.say();

    }

}
